﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GeoUtils
{
    public class BoundRect
    {
        private LatLong _northEastCorner;
        private LatLong _southWestCorner;


        public LatLong NorthEastCorner
        {
            get { return _northEastCorner; }
            set { _northEastCorner = value; }
        }

        public LatLong SouthWestCorner
        {
            get { return _southWestCorner; }
            set { _southWestCorner = value; }
        }


        public BoundRect(LatLong ne, LatLong sw)
        {
            _northEastCorner = ne;
            _southWestCorner = sw;
        }

        public BoundRect(BoundRect br)
        {
            this.NorthEastCorner = br.NorthEastCorner;
            this.SouthWestCorner = br.SouthWestCorner;
        }

      

        public LatLong Center
        {
            get
            {
                double longitude = (_northEastCorner.Longitude + _southWestCorner.Longitude) / 2.0;
                double latitude = (_northEastCorner.Latitude + _southWestCorner.Latitude) / 2.0;
                return new LatLong(longitude, latitude);
            }
        }

        public bool IsPointIn(LatLong point)
        {
            return IsPointIn(point.Longitude, point.Latitude);
        }

        public bool IsPointIn(double longitude, double latitude)
        {
            return longitude >= _southWestCorner.Longitude && 
                longitude <= _northEastCorner.Longitude && 
                latitude >= _southWestCorner.Latitude && 
                latitude <= _northEastCorner.Latitude;
        }
    }
}
